home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 2000
/
MacHack 2000.toast
/
pc
/
The Hacks
/
Softshoe
/
Lisa's Mac Parts
/
Heap
/
Heap.h
< prev
next >
Wrap
Text File
|
2000-06-23
|
1KB
|
62 lines
// Heap.h
#ifndef Heap_h
#define Heap_h
#ifndef Integers_h
#include "Integers.h"
#endif
#ifndef Assert_h
#include "Assert.h"
#endif
template < class Element > class HeapLink;
template < class Element >
class Heap
{
typedef Element ElementType;
typedef HeapLink< Element > LinkType;
typedef Heap< Element > HeapType;
typedef bool (ElementType::*Comparator)( const Element& ) const;
private:
uint32 nodeCount;
LinkType *top;
const Comparator below;
LinkType** SubHeap( uint32 path );
LinkType& RemoveLast();
void SinkNode( LinkType**& subHeap, LinkType*& newNode );
void Percolate( LinkType** subHeap );
void Validate( LinkType& node, uint32 level ) const;
// Implemented only to allow explicit instantiation
Heap( const Heap& ) { Assert( 0 ); }
void operator=( const Heap& ) { Assert( 0 ); }
public:
Heap( Comparator below ); // Typically operator<=( const Element& ) const
~Heap();
Comparator Below() const { return below; }
bool IsEmpty() const { return top == 0; }
LinkType& Top() const { Assert( top != 0 ); return *top; }
LinkType& Pop();
void Add( LinkType& );
void Remove( LinkType& );
void Validate() const; // Checks a set of assertions
};
#ifndef Heap_cp
#include "Heap.cp"
#endif
#endif